package com.usian.wemedia.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.wemedia.WmUserControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.media.dtos.WmUserDto;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController implements WmUserControllerApi {
    @Autowired
    WmUserService service;
    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmUser wmUser) {
        service.save(wmUser);
        return ResponseResult.okResult(wmUser);
    }

    @Override
    @GetMapping("/findByName/{name}")
    public WmUser findByName(@PathVariable String name) {
        return service.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName,name));
    }

    @Override
    @PostMapping("/in")
    public ResponseResult login(@RequestBody WmUserDto dto) {
        return service.login(dto);
    }

    @PostMapping("/updateById")
    public ResponseResult updateById(@RequestBody WmUser wmUser) {
        service.updateById(wmUser);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
